<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head th:include="include/admin/adminHeader::html('数据管理')"></head>
<body>
<div th:replace="include/admin/adminNavigator::html"></div>
<script>
    $(function () {
        var data4Vue = {
            uri: 'temp_products',
            add_uri: 'products',
            pagination: {},
            bean: {
                id: 0,
                name: '',
                sizex: '',
                sizey: '',
                sizez: '',
                nX: '',
                nY: '',
                strainX: '',
                strainY: '',
                elecX: '',
                elecY: '',
                elecZ: '',
                dataType: '',
                Doi: '',
                SupplmentaryInfo: ''
            },
            beans: [],
            //Imagfile: null,
            // file:null,
        };

        //ViewModel
        var vue = new Vue({
            el: '#workingArea',
            data: data4Vue,
            mounted: function () { //mounted　表示这个 Vue 对象加载成功了
                this.list(0);
            },
            methods: {
                list: function (start) {
                    var url = this.uri + "?start=" + start;
                    axios.get(url).then(function (response) {
                        vue.pagination = response.data;
                        vue.beans = response.data.content;
                    });
                },
                add: function (id) {
                    var url = this.uri + "/" + id;
                    axios.get(url).then(function (response) {
                        vue.bean= response.data;
                        var formData = new FormData();
                        // bean: {id: 0, name: '', sizex: '', sizey: '', sizez: '',nX:'',nY:'',strainX:'',strainY:'',elecX:'',elecY:'',
                        //elecZ:'',datetype:'',Doi:'',SupplmentaryInfo:''},
                        formData.append("name", vue.bean.name);
                        formData.append("sizex", vue.bean.sizex);
                        formData.append("sizey", vue.bean.sizey);
                        formData.append("sizez", vue.bean.sizez);
                        formData.append("nX", vue.bean.nX);
                        formData.append("nY", vue.bean.nY);
                        formData.append("strainX", vue.bean.strainX);
                        formData.append("strainY", vue.bean.strainY);
                        formData.append("elecX", vue.bean.elecX);
                        formData.append("elecY", vue.bean.elecY);
                        formData.append("elecZ", vue.bean.elecZ);
                        formData.append("dataType", vue.bean.dataType);
                        formData.append("Doi", vue.bean.Doi);
                        formData.append("SupplmentaryInfo", vue.bean.SupplmentaryInfo);
                        console.log(formData)
                        axios.post("add_products/", formData).then(function (response) {
                            vue.list(0);
                            vue.bean = {
                                id: 0,
                                name: '',
                                sizex: '',
                                sizey: '',
                                sizez: '',
                                nX: '',
                                nY: '',
                                strainX: '',
                                strainY: '',
                                ElecX: '',
                                ElecY: '',
                                ElecZ: '',
                                datetype: ''
                            };
                        });
                    });
                }
                ,
                //删除数据
                deleteBean: function (id) {
                    if (!checkDeleteLink())
                        return;
                    var url = this.uri + "/" + id;
                    axios.delete(url).then(function (response) {
                        if (0 != response.data.length) {
                            alert(response.data);
                        } else {
                            vue.list(0);
                        }
                    });
                },
                jump: function (page) {
                    jump(page, vue); //定义在adminHeader.html 中
                },
                jumpByNumber: function (start) {
                    jumpByNumber(start, vue);
                }
            }
        });
    });

</script>
<div id="workingArea">
    <h1 class="label label-info">数据管理</h1>
    <br>
    <br>
    <div class="listDataTableDiv">
        <table class="table table-striped table-bordered table-hover  table-condensed">
            <thead>
            <tr class="success">
                <th>ID</th>
                <th>名字</th>
                <th>sizex</th>
                <th>sizey</th>
                <th>sizez</th>
                <th>NX</th>
                <th>NY</th>
                <th>strainX</th>
                <th>strainY</th>
                <th>ElecX</th>
                <th>ElecY</th>
                <th>ElecZ</th>
                <th>Datatype</th>
                <th>图片</th>
                <th>添加至标准库</th>
                <th>编辑</th>
                <th>删除</th>
            </tr>
            </thead>
            <tbody>

            <tr v-for="bean in beans ">
                <td>{{bean.id}}</td>
                <td>
                    {{bean.name}}
                </td>
                <td>
                    {{bean.sizex}}
                </td>
                <td>
                    {{bean.sizey}}
                </td>
                <td>
                    {{bean.sizez}}
                </td>
                <td>
                    {{bean.nX}}
                </td>
                <td>
                    {{bean.nY}}
                </td>
                <td>
                    {{bean.strainX}}
                </td>
                <td>
                    {{bean.strainY}}
                </td>
                <td>
                    {{bean.elecX}}
                </td>
                <td>
                    {{bean.elecY}}
                </td>
                <td>
                    {{bean.elecZ}}
                </td>
                <td>
                    {{bean.dataType}}

                </td>
                <!--TODO  -->
                <td>

                </td>
                <td>
                    <a href="#nowhere" @click="add(bean.id)"><span class="glyphicon glyphicon-plus"></span></a>
                </td>

                <td>
                    <a :href="'admin_temp_product_edit?id='+ bean.id"><span class="glyphicon glyphicon-edit"></span></a>
                </td>
                <td>
                    <a href="#nowhere" @click="deleteBean(bean.id)"><span
                            class="   glyphicon glyphicon-trash"></span></a>
                </td>
            </tr>
            </tbody>
        </table>
    </div>
    <div th:replace="include/admin/adminPage::html"></div>
</div>
<div th:replace="include/admin/adminFooter::html"></div>
</body>
</html>